'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async userList() {
    const { ctx, app } = this;

    // 获取用户列表
    const data = await app.mysql.select('userlist');

    ctx.body = {
      code: 1,
      data,
    };
  }

  // 修改用户权限
  async editRule() {
    const { ctx, app } = this;

    // 获取前端传来的参数
    const { id, rule } = ctx.request.body;

    // 更改权限
    await app.mysql.update('userlist', { id, rule });

    ctx.body = {
      code: 1,
      msg: '权限更改成功',
    };
  }

}

module.exports = HomeController;
